package com.xw.bo.ks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xw.bo.ks.service.KsActivityInfoService;
import com.xw.bo.ks.mapper.KsActivityInfoMapper;
import org.springframework.stereotype.Service;
import com.xw.bo.ks.entity.KsActivityInfo;

import org.springframework.beans.BeanUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.xw.bo.ks.entity.bean.KsActivityInfoReq;
import com.xw.bo.ks.entity.bean.KsActivityInfoQo;
import com.xw.bo.ks.util.XwUtil;
import org.apache.commons.lang3.StringUtils;

import com.xw.bo.ks.entity.base.BoPage;
import com.xw.bo.ks.entity.base.HeadDataPage;

import javax.annotation.Resource;

/**
 * @author： xw ftl auto
 * @create： 2024-06-20 15:45:31
 */
@Service
public class KsActivityInfoServiceImpl extends ServiceImpl<KsActivityInfoMapper, KsActivityInfo> implements KsActivityInfoService {

    @Resource
    private KsActivityInfoMapper ksActivityInfoMapper;

    @Override
    public BoPage<KsActivityInfo> pageSampleKsActivityInfo(Integer pageNumber, Integer pageSize) {

        HeadDataPage headDataPage = new HeadDataPage();
        headDataPage.setPageNumber(pageNumber);
        headDataPage.setPageSize(pageSize);

        return boPageBean(new QueryWrapper<>(), headDataPage);
    }

    @Override
    public BoPage<KsActivityInfo> pageEqKsActivityInfoDto(KsActivityInfoReq ksActivityInfoReq) {

        KsActivityInfo queryKsActivityInfo = new KsActivityInfo();
        BeanUtils.copyProperties(ksActivityInfoReq, queryKsActivityInfo);

        LambdaQueryWrapper<KsActivityInfo> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(null != ksActivityInfoReq.getKsActivityInfoId(),KsActivityInfo::getId, ksActivityInfoReq.getKsActivityInfoId());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityId(),KsActivityInfo::getActivityId, ksActivityInfoReq.getActivityId());
        queryWrapper.eq(null != ksActivityInfoReq.getCompanyId(),KsActivityInfo::getCompanyId, ksActivityInfoReq.getCompanyId());
        queryWrapper.eq(null != ksActivityInfoReq.getPartnerId(),KsActivityInfo::getPartnerId, ksActivityInfoReq.getPartnerId());
        queryWrapper.eq(null != ksActivityInfoReq.getPartnerName(),KsActivityInfo::getPartnerName, ksActivityInfoReq.getPartnerName());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityTitle(),KsActivityInfo::getActivityTitle, ksActivityInfoReq.getActivityTitle());
        queryWrapper.eq(null != ksActivityInfoReq.getExistsActivityId(),KsActivityInfo::getExistsActivityId, ksActivityInfoReq.getExistsActivityId());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityUserNickName(),KsActivityInfo::getActivityUserNickName, ksActivityInfoReq.getActivityUserNickName());
        queryWrapper.eq(null != ksActivityInfoReq.getMinInvestmentPromotionRate(),KsActivityInfo::getMinInvestmentPromotionRate, ksActivityInfoReq.getMinInvestmentPromotionRate());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityUserId(),KsActivityInfo::getActivityUserId, ksActivityInfoReq.getActivityUserId());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityBeginTime(),KsActivityInfo::getActivityBeginTime, ksActivityInfoReq.getActivityBeginTime());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityEndTime(),KsActivityInfo::getActivityEndTime, ksActivityInfoReq.getActivityEndTime());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityType(),KsActivityInfo::getActivityType, ksActivityInfoReq.getActivityType());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityStatus(),KsActivityInfo::getActivityStatus, ksActivityInfoReq.getActivityStatus());
        queryWrapper.eq(null != ksActivityInfoReq.getMinItemCommissionRate(),KsActivityInfo::getMinItemCommissionRate, ksActivityInfoReq.getMinItemCommissionRate());
        queryWrapper.eq(null != ksActivityInfoReq.getAuditPassItemCount(),KsActivityInfo::getAuditPassItemCount, ksActivityInfoReq.getAuditPassItemCount());
        queryWrapper.eq(null != ksActivityInfoReq.getWaitAuditItemCount(),KsActivityInfo::getWaitAuditItemCount, ksActivityInfoReq.getWaitAuditItemCount());
        queryWrapper.eq(null != ksActivityInfoReq.getApplyItemCount(),KsActivityInfo::getApplyItemCount, ksActivityInfoReq.getApplyItemCount());
        queryWrapper.eq(null != ksActivityInfoReq.getCustomerPrice(),KsActivityInfo::getCustomerPrice, ksActivityInfoReq.getCustomerPrice());
        queryWrapper.eq(null != ksActivityInfoReq.getActivityCount(),KsActivityInfo::getActivityCount, ksActivityInfoReq.getActivityCount());
        queryWrapper.eq(null != ksActivityInfoReq.getDistributeItemOrderCount(),KsActivityInfo::getDistributeItemOrderCount, ksActivityInfoReq.getDistributeItemOrderCount());
        queryWrapper.eq(null != ksActivityInfoReq.getDistributeTradeSellerCount(),KsActivityInfo::getDistributeTradeSellerCount, ksActivityInfoReq.getDistributeTradeSellerCount());
        queryWrapper.eq(null != ksActivityInfoReq.getDistributeTradeItemCount(),KsActivityInfo::getDistributeTradeItemCount, ksActivityInfoReq.getDistributeTradeItemCount());
        queryWrapper.eq(null != ksActivityInfoReq.getTips(),KsActivityInfo::getTips, ksActivityInfoReq.getTips());
        queryWrapper.eq(null != ksActivityInfoReq.getPromoterId(),KsActivityInfo::getPromoterId, ksActivityInfoReq.getPromoterId());
        queryWrapper.eq(null != ksActivityInfoReq.getFullTime(),KsActivityInfo::getFullTime, ksActivityInfoReq.getFullTime());
        queryWrapper.eq(null != ksActivityInfoReq.getIsDelete(),KsActivityInfo::getIsDelete, ksActivityInfoReq.getIsDelete());
        queryWrapper.eq(null != ksActivityInfoReq.getDeletedAt(),KsActivityInfo::getDeletedAt, ksActivityInfoReq.getDeletedAt());
        queryWrapper.eq(null != ksActivityInfoReq.getCreatedAt(),KsActivityInfo::getCreatedAt, ksActivityInfoReq.getCreatedAt());
        queryWrapper.eq(null != ksActivityInfoReq.getUpdatedAt(),KsActivityInfo::getUpdatedAt, ksActivityInfoReq.getUpdatedAt());
        queryWrapper.eq(null != ksActivityInfoReq.getCreatedYmd(),KsActivityInfo::getCreatedYmd, ksActivityInfoReq.getCreatedYmd());

        if (StringUtils.isNotEmpty(ksActivityInfoReq.getStartTime())) {
            Integer startTime = XwUtil.parseToInteger(ksActivityInfoReq.getStartTime());
            queryWrapper.ge(KsActivityInfo::getCreatedAt, startTime);
        }
        if (StringUtils.isNotEmpty(ksActivityInfoReq.getEndTime())) {
            Integer endTime = XwUtil.parseToInteger(ksActivityInfoReq.getEndTime());
            queryWrapper.le(KsActivityInfo::getCreatedAt, endTime);
        }

        queryWrapper.orderByDesc(KsActivityInfo::getCreatedAt);

        return boPageBean(queryWrapper, ksActivityInfoReq);
    }


    @Override
    public BoPage<KsActivityInfo> pageKsActivityInfoMapper(KsActivityInfoReq ksActivityInfoReq) {
        if (!"desc".equals(ksActivityInfoReq.getOrderValue()) && !"aes".equals(ksActivityInfoReq.getOrderValue())) {
            ksActivityInfoReq.setOrderValue("desc");
        }

        KsActivityInfoQo ksActivityInfoQo = new KsActivityInfoQo();
        BeanUtils.copyProperties(ksActivityInfoReq,ksActivityInfoQo);

        if (ksActivityInfoReq.getKsActivityInfoId() != null){
            ksActivityInfoQo.setId(ksActivityInfoReq.getKsActivityInfoId());
        }

        if (StringUtils.isNotEmpty(ksActivityInfoReq.getStartTime())) {
            Integer startTime = XwUtil.parseToInteger(ksActivityInfoReq.getStartTime());
            ksActivityInfoQo.setStartTime(startTime);
        }
        if (StringUtils.isNotEmpty(ksActivityInfoReq.getEndTime())) {
            Integer endTime = XwUtil.parseToInteger(ksActivityInfoReq.getEndTime());
            ksActivityInfoQo.setEndTime(endTime);
        }

        return boPageBeanBack(new QueryWrapper<>(), ksActivityInfoReq, wrapper -> ksActivityInfoMapper.pageKsActivityInfoMapper(ksActivityInfoQo));
    }


}
